package lesson04;

import java.util.Scanner;

/**
 * 双色球主控制流程类
 */
public class DoubleBall {
    private Ball [] systemRedBalls = new Ball[6];
    private Ball systemBlueBall;
    private Ball [] inputRedBalls = new Ball[6];
    private Ball inputBlueBall;
    private Scanner sc = new Scanner(System.in);
    public DoubleBall(){
        generateSystemBall();
        inputBall();
        printResult();
    }
    /**
     * 随机产生系统的中奖号码
     */
    public void generateSystemBall(){
        for(int i = 0;i < systemRedBalls.length;i++){
            systemRedBalls[i] = new Ball("red");
            for(int j = 0;j < i;j++){
                if(systemRedBalls[i].getValue()
                        == systemRedBalls[j].getValue()){
                    i--;
                    break;
                }
            }
            System.out.println(systemRedBalls[i].getValue());
        }
        systemBlueBall = new Ball("blue");
        System.out.println(systemBlueBall.getValue());
    }
    /**
     * 用户输入中奖号码
     */
    public void inputBall(){
        for(int i = 0;i < inputRedBalls.length;i++){
            System.out.println("请输入第"+(i + 1)+"颗红球：");
            inputRedBalls[i] = new Ball(sc.nextInt());
            for(int j = 0;j < i;j++){
                if(inputRedBalls[i].getValue() == inputRedBalls[j].getValue()){
                    i--;
                    System.out.println("红球重复，请重新输入");
                    break;
                }
            }
        }
        System.out.println("请输入蓝球：");
        inputBlueBall = new Ball(sc.nextInt());
    }
    /**
     * 给出中奖结果
     */
    public void printResult(){
        int redBallCount = 0;
        for(int i = 0;i < systemRedBalls.length;i++){
            for(int j = 0;j < inputRedBalls.length;j++){
                if(systemRedBalls[i].getValue() == inputRedBalls[j].getValue()){
                    redBallCount++;
                }
            }
        }
        if(redBallCount == 6 && systemBlueBall.getValue() == inputBlueBall.getValue()){
            System.out.println("恭喜，中了一等奖");
        }else if(redBallCount == 6){
            System.out.println("恭喜，中了二等奖");
        }else if(redBallCount == 5 && systemBlueBall.getValue() == inputBlueBall.getValue()){
            System.out.println("恭喜，中了三等奖");
        }else if(redBallCount == 5 || redBallCount == 4
                && systemBlueBall.getValue() == inputBlueBall.getValue()){
            System.out.println("恭喜，中了四等奖");
        }else if(redBallCount == 4 || redBallCount == 3
                && systemBlueBall.getValue() == inputBlueBall.getValue()){
            System.out.println("恭喜，中了五等奖");
        }else if(systemBlueBall.getValue() == inputBlueBall.getValue()){
            System.out.println("恭喜，中了六等奖");
        }else{
            System.out.println("很遗憾，没中奖");
        }

    }

    public static void main(String[] args) {
        DoubleBall doubleBall = new DoubleBall();
//        doubleBall.generateSystemBall();
//        for(int i = 0;i < doubleBall.systemRedBalls.length;i++){
//            System.out.println(doubleBall.systemRedBalls[i].getValue());
//        }
//        doubleBall.inputBall();

    }
}
